1 /* 2 * This file is part of gtkD. 3 * 4 * gtkD is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU Lesser General Public License 6 * as published by the Free Software Foundation; either version 3 7 * of the License, or (at your option) any later version, with 8 * some exceptions, please read the COPYING file. 9 * 10 * gtkD is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Lesser General Public License for more details. 14 * 15 * You should have received a copy of the GNU Lesser General Public License 16 * along with gtkD; if not, write to the Free Software 17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA 18 */ 19 20 // generated automatically - do not change 21 // find conversion definition on APILookup.txt 22 // implement new conversion functionalities on the wrap.utils pakage 23 24 25 module sourceview.CompletionContext; 26 27 private import gio.ListModelIF; 28 private import gio.ListModelT; 29 private import glib.MemorySlice; 30 private import glib.Str; 31 private import glib.c.functions; 32 private import gobject.ObjectG; 33 private import gtk.TextIter; 34 private import sourceview.Buffer; 35 private import sourceview.Completion; 36 private import sourceview.CompletionProviderIF; 37 private import sourceview.Language; 38 private import sourceview.View; 39 private import sourceview.c.functions; 40 public import sourceview.c.types; 41 42 43 /** 44 * The context of a completion. 45 * 46 * `GtkSourceCompletionContext` contains information about an attept to display 47 * completion proposals to the user based on typed text in the [class@View]. 48 * 49 * When typing, [class@Completion] may use registered 50 * [iface@CompletionProvider] to determine if there may be results which 51 * could be displayed. If so, a `GtkSourceCompletionContext` is created with 52 * information that is provided to the [iface@CompletionProvider] to populate 53 * results which might be useful to the user. 54 * 55 * [iface@CompletionProvider] are expected to provide [iface@Gio.ListModel] with 56 * [iface@CompletionProposal] which may be joined together in a list of 57 * results for the user. They are also responsible for how the contents are 58 * displayed using [class@CompletionCell] which allows for some level of 59 * customization. 60 */ 61 public class CompletionContext : ObjectG, ListModelIF 62 { 63 /** the main Gtk struct */ 64 protected GtkSourceCompletionContext* gtkSourceCompletionContext; 65 66 /** Get the main Gtk struct */ 67 public GtkSourceCompletionContext* getCompletionContextStruct(bool transferOwnership = false) 68 { 69 if (transferOwnership) 70 ownedRef = false; 71 return gtkSourceCompletionContext; 72 } 73 74 /** the main Gtk struct as a void* */ 75 protected override void* getStruct() 76 { 77 return cast(void*)gtkSourceCompletionContext; 78 } 79 80 /** 81 * Sets our main struct and passes it to the parent class. 82 */ 83 public this (GtkSourceCompletionContext* gtkSourceCompletionContext, bool ownedRef = false) 84 { 85 this.gtkSourceCompletionContext = gtkSourceCompletionContext; 86 super(cast(GObject*)gtkSourceCompletionContext, ownedRef); 87 } 88 89 // add the ListModel capabilities 90 mixin ListModelT!(GtkSourceCompletionContext); 91 92 93 /** */ 94 public static GType getType() 95 { 96 return gtk_source_completion_context_get_type(); 97 } 98 99 /** 100 * Gets the mode for which the context was activated. 101 */ 102 public GtkSourceCompletionActivation getActivation() 103 { 104 return gtk_source_completion_context_get_activation(gtkSourceCompletionContext); 105 } 106 107 /** 108 * Gets the bounds for the completion, which is the beginning of the 109 * current word (taking break characters into account) to the current 110 * insertion cursor. 111 * 112 * If @begin is non-%NULL, it will be set to the start position of the 113 * current word being completed. 114 * 115 * If @end is non-%NULL, it will be set to the insertion cursor for the 116 * current word being completed. 117 * 118 * Params: 119 * begin = a #GtkTextIter 120 * end = a #GtkTextIter 121 * 122 * Returns: %TRUE if the marks are still valid and @begin or @end was set. 123 */ 124 public bool getBounds(out TextIter begin, out TextIter end) 125 { 126 GtkTextIter* outbegin = sliceNew!GtkTextIter(); 127 GtkTextIter* outend = sliceNew!GtkTextIter(); 128 129 auto __p = gtk_source_completion_context_get_bounds(gtkSourceCompletionContext, outbegin, outend) != 0; 130 131 begin = ObjectG.getDObject!(TextIter)(outbegin, true); 132 end = ObjectG.getDObject!(TextIter)(outend, true); 133 134 return __p; 135 } 136 137 /** 138 * Gets the underlying buffer used by the context. 139 * 140 * This is a convenience function to get the buffer via the #GtkSourceCompletion 141 * property. 142 * 143 * Returns: a #GtkTextBuffer or %NULL 144 */ 145 public Buffer getBuffer() 146 { 147 auto __p = gtk_source_completion_context_get_buffer(gtkSourceCompletionContext); 148 149 if(__p is null) 150 { 151 return null; 152 } 153 154 return ObjectG.getDObject!(Buffer)(cast(GtkSourceBuffer*) __p); 155 } 156 157 /** 158 * Gets the "busy" property. This is set to %TRUE while the completion 159 * context is actively fetching proposals from registered 160 * #GtkSourceCompletionProvider's. 161 * 162 * Returns: %TRUE if the context is busy 163 */ 164 public bool getBusy() 165 { 166 return gtk_source_completion_context_get_busy(gtkSourceCompletionContext) != 0; 167 } 168 169 /** 170 * Gets the #GtkSourceCompletion that created the context. 171 * 172 * Returns: an #GtkSourceCompletion or %NULL 173 */ 174 public Completion getCompletion() 175 { 176 auto __p = gtk_source_completion_context_get_completion(gtkSourceCompletionContext); 177 178 if(__p is null) 179 { 180 return null; 181 } 182 183 return ObjectG.getDObject!(Completion)(cast(GtkSourceCompletion*) __p); 184 } 185 186 /** 187 * Checks if any proposals have been provided to the context. 188 * 189 * Out of convenience, this function will return %TRUE if @self is %NULL. 190 * 191 * Returns: %TRUE if there are no proposals in the context 192 */ 193 public bool getEmpty() 194 { 195 return gtk_source_completion_context_get_empty(gtkSourceCompletionContext) != 0; 196 } 197 198 /** 199 * Gets the language of the underlying buffer, if any. 200 * 201 * Returns: a #GtkSourceLanguage or %NULL 202 */ 203 public Language getLanguage() 204 { 205 auto __p = gtk_source_completion_context_get_language(gtkSourceCompletionContext); 206 207 if(__p is null) 208 { 209 return null; 210 } 211 212 return ObjectG.getDObject!(Language)(cast(GtkSourceLanguage*) __p); 213 } 214 215 /** 216 * Gets the text view for the context. 217 * 218 * Returns: a #GtkSourceView or %NULL 219 */ 220 public View getView() 221 { 222 auto __p = gtk_source_completion_context_get_view(gtkSourceCompletionContext); 223 224 if(__p is null) 225 { 226 return null; 227 } 228 229 return ObjectG.getDObject!(View)(cast(GtkSourceView*) __p); 230 } 231 232 /** 233 * Gets the word that is being completed up to the position of the insert mark. 234 * 235 * Returns: a string containing the current word 236 */ 237 public string getWord() 238 { 239 auto retStr = gtk_source_completion_context_get_word(gtkSourceCompletionContext); 240 241 scope(exit) Str.freeString(retStr); 242 return Str.toString(retStr); 243 } 244 245 /** 246 * This function allows providers to update their results for a context 247 * outside of a call to [method@CompletionProvider.populate_async]. 248 * 249 * This can be used to immediately return results for a provider while it does 250 * additional asynchronous work. Doing so will allow the completions to 251 * update while the operation is in progress. 252 * 253 * Params: 254 * provider = an #GtkSourceCompletionProvider 255 * results = a #GListModel or %NULL 256 */ 257 public void setProposalsForProvider(CompletionProviderIF provider, ListModelIF results) 258 { 259 gtk_source_completion_context_set_proposals_for_provider(gtkSourceCompletionContext, (provider is null) ? null : provider.getCompletionProviderStruct(), (results is null) ? null : results.getListModelStruct()); 260 } 261 }